//
//  NSAttributedString+Extension.swift
//  YANAWeibo
//
//  Created by mac on 16/5/24.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

extension NSAttributedString {
    // 根据表情模型和字体创建一个富文本对象
    class func attributedWithEmoticon(emticon: SYEmoticon, font: UIFont) -> NSAttributedString {
        // 根据表情图片路径创建一个UIimage
        let image = UIImage(named: emticon.path!)
        let attachment = SYTextAttachment()
        attachment.emoticon = emticon
        attachment.image = image
        
        let fontHeight = font.lineHeight
        attachment.bounds = CGRect(x: 0, y: -4, width: fontHeight, height: fontHeight)
        
        let attributeStr = NSAttributedString(attachment: attachment)
        return attributeStr
    }
}
